package org.example.acm;

import java.util.*;

public class WanderingEarthSolution {

    public static void mainArrays(String[] args) {
        //处理输入
        Scanner scanner = new Scanner(System.in);
        String[] countArr = scanner.nextLine().split(" ");
        int total = Integer.parseInt(countArr[0]);
        int byHand = Integer.parseInt(countArr[1]);
        TreeMap<Integer, List<Integer>> map = new TreeMap<>();
        for (int i=0;i<byHand;i++) {
            String[] line = scanner.nextLine().split(" ");
            Integer launchTime = Integer.parseInt(line[0]);
            List<Integer> list = map.getOrDefault(launchTime, new ArrayList<>());
            list.add(Integer.parseInt(line[1]));
            map.put(launchTime, list);
        }

        Queue<Integer> queue = new LinkedList<>();
        int launched = 0;
        int d = 0;
        boolean[] started = new boolean[total];
        int lastSize = 0;
        List<Integer> lastIndexList = new ArrayList<>();
        while (launched < total) {
            if (queue.isEmpty()) {
                Integer key = map.firstKey();
                queue.addAll(map.get(key));
                map.remove(key);
                d = key;
            } else {
                if (map.containsKey(d)) {
                    queue.addAll(map.get(d));
                }
            }
            int size = queue.size();
            lastSize = 0;
            lastIndexList = new ArrayList<>();
            for (int i=0;i<size;i++) {
                int index = queue.poll();
                if (!started[index]) {
                    started[index] = true;
                    launched++;
                    lastSize++;
                    lastIndexList.add(index);
                } else {
                    continue;
                }
                int nextIndex = (index+1) % total;
                int preIndex = (index-1+total) % total;
                if (!started[nextIndex]) {
                    queue.add(nextIndex);
                }
                if (!started[preIndex]) {
                    queue.add(preIndex);
                }
            }
            d++;
        }

        //输出结果
        System.out.println(lastSize);
        Collections.sort(lastIndexList);
        for (int i=0;i<lastIndexList.size();i++) {
            System.out.print(lastIndexList.get(i));
            if (i < lastIndexList.size()-1) {
                System.out.print(" ");
            }
        }

        scanner.close();
    }
}
